package com.agentworkflow.engine.core.model.node.event;

import com.agentworkflow.engine.core.enums.TriggerConfigType;
import lombok.Getter;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

@Getter
@ToString
public class TriggerConfig {

    private String type = TriggerConfigType.MANUAL.getCode();

    private Map<String, Object> settings = new HashMap<>();

    private TriggerConfig() {}

    public static TriggerConfig manualConfig() {
        TriggerConfig triggerConfig = new TriggerConfig();
        triggerConfig.type =  TriggerConfigType.MANUAL.getCode();
        return triggerConfig;
    }

    public static TriggerConfig apiConfig(String endPoint, String method) {
        TriggerConfig triggerConfig = new TriggerConfig();
        triggerConfig.type = TriggerConfigType.API.getCode();
        triggerConfig.settings = new HashMap<>();
        triggerConfig.settings.put("endPoint", endPoint);
        triggerConfig.settings.put("method", method);
        return triggerConfig;
    }

    public static TriggerConfig schedulerConfig(String cron) {
        TriggerConfig triggerConfig = new TriggerConfig();
        triggerConfig.type = TriggerConfigType.SCHEDULE.getCode();
        triggerConfig.settings = new HashMap<>();
        triggerConfig.settings.put("cron_expression", cron);
        return triggerConfig;
    }

    public static TriggerConfig webHookConfig(String url) {
        TriggerConfig triggerConfig = new TriggerConfig();
        triggerConfig.type = TriggerConfigType.WEBHOOK.getCode();
        triggerConfig.settings = new HashMap<>();
        triggerConfig.settings.put("webhook_url", url);
        return triggerConfig;
    }
}
